package com.service.loan.controller;

import com.client.model.pojo.loan.AiruiLoan;
import com.client.model.pojo.loan.AiruiLoanProduct;
import com.client.model.vo.common.Result;
import com.client.model.vo.common.ResultCodeEnum;
import com.client.model.vo.creditLoanVo.LoanVo;
import com.client.model.vo.creditLoanVo.RulerVo;
import com.client.model.vo.userVo.ArUserVo;
import com.service.loan.feignService.UserFeignCreditCardService;
import com.service.loan.service.AiruiLoanProductService;
import com.service.loan.service.AiruiLoanService;
import com.service.loan.service.AiruiRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : RulerWood
 * @Data : 2024/4/9 - 13:54
 */
@Tag(name = "贷款接口")
@RestController
@RequestMapping("/airui/api/loan")
public class LoanController {
    @Autowired
    private AiruiLoanProductService airuiLoanProductService;
    @Autowired
    private AiruiRecordService airuiRecordService;
    @Autowired
    private AiruiLoanService airuiLoanService;

    /**
     * 查看所有可贷款产品
     *
     * @return
     */
    @GetMapping("/product")
    @Operation(summary = "贷款产品")
    public Result<List<AiruiLoanProduct>> getProduct() {
        return Result.build(airuiLoanProductService.list(), ResultCodeEnum.SUCCESS);
    }

    /**
     * 贷款申请
     *
     * @param loanVo 用户传入的信息
     * @return
     */
    @PostMapping("/loan")
    @Operation(summary = "贷款申请")
    public Result<String> loan(@RequestBody LoanVo loanVo,@RequestHeader("token") String token) {
        return this.airuiRecordService.loan(loanVo,token);
    }

    /**
     * 当前用户的贷款信息
     * @param token 用户登录token
     * @return
     */
    @GetMapping("/myLoan")
    @Operation(summary = "我的贷款信息")
    public Result<List<AiruiLoan>> myLoan(@RequestHeader("token") String token) {
        return this.airuiLoanService.myLoan(token);
    }

    /**
     * 还款
     * @param rulerVo 用户的信息
     * @param token   用户的登录头信息
     * @return
     */
    @PostMapping("/reBackLoan")
    @Operation(summary = "还款")
    public Result<String> reBackLoan(@RequestBody RulerVo rulerVo, @RequestHeader String token) {
        return this.airuiLoanService.reBackLoan(rulerVo,token);
    }

    @PostMapping("/canAffordIt")
    @Operation(summary = "判断主卡是否可以还款")
    public Result<String> canAffordIt(RulerVo rulerVo,@RequestHeader("token") String token) {
        return this.airuiLoanService.canAffordIt(rulerVo,token);
    }


}
